package com.calmcar.adas.service;

import android.content.Context;
import android.content.res.AssetManager;

import com.xml.encrypt.util.DesUtil;

import java.io.File;
import java.io.InputStream;

/**
 * Created by lelexiao on 2018/5/5.
 */

public class FileProcessServer {

    public static void setLDWConf(Context mContext , String kmiStr ){
//        String kmiStr=ldwManager.generateKmmiStr();
//        CdwServer.kmiStr= kmiStr;
        copyFileFromRes("config.txt","/mnt/sdcard/test" ,mContext,kmiStr);
    }

    public static void setCDWConf(Context mContext ,String kmiStr){
        copyFileFromRes("car_lbp_init_config.xml","/mnt/sdcard/test" ,mContext,kmiStr);
    }
    public static void setCDWConfForHalf(Context mContext ,String kmiStr){
        copyFileFromRes("car_lbp_init_config_half.xml","/mnt/sdcard/test" ,mContext,kmiStr);
    }

    private static  void copyFileFromRes(String fileName, String storagePath,Context mContext,String kmi){
        try{
            AssetManager am = mContext.getAssets();
            InputStream inputStream= am.open(fileName);
            File file = new File(storagePath);
            if (!file.exists()) {//如果文件夹不存在，则创建新的文件夹
                file.mkdirs();
            }
            File storeFile = new File(file , fileName);
            DesUtil.saveFileNew(storeFile  , inputStream,kmi);
            inputStream.close();
        }catch (Exception e ){
            e.printStackTrace();
        }
    }

}
